package com.cw.serviceimpl;

import com.cw.data.PageBean;
import com.cw.mapper.TbBrandMapper;
import com.cw.pojo.TbBrand;
import com.cw.service.BrandService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@com.alibaba.dubbo.config.annotation.Service
public class BrandServiceImpl implements BrandService {

    @Autowired
    private TbBrandMapper tbBrandMapper;

    @Override
    public PageBean<TbBrand> getBrandInfo(Integer pageNumber, Integer pageSize) {

        PageHelper.startPage(pageNumber, pageSize);

        List<TbBrand> brandList = tbBrandMapper.selectByExample(null);

        PageInfo<TbBrand> pa = new PageInfo<>(brandList);

        return new PageBean(pa.getPageNum(), pa.getPageSize(), pa.getPages(), pa.getTotal(), pa.getList());
    }

    @Override
    public void addBrand(TbBrand tbBrand) {

        System.out.println(tbBrand.getName());

        tbBrandMapper.insertSelective(tbBrand);
    }

    @Override
    public TbBrand getOneBrandInfo(Long id) {

        return tbBrandMapper.selectByPrimaryKey(id);
    }

    @Override
    public void updateBrand(TbBrand tbBrand) {
        tbBrandMapper.updateByPrimaryKeySelective(tbBrand);
    }

    @Override
    public void deleteBrand(Long[] id) {

        tbBrandMapper.deleteBrand(id);
    }
}
